package com.momo.hotel.controller;

import com.momo.hotel.dao.pojo.TbFeedback;
import com.momo.hotel.dao.pojo.TbUser;
import com.momo.hotel.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author qiang
 * @create 2019/7/5
 */
@Controller
public class FeedbackController {
    @Autowired
    FeedbackService feedbackService;

    @ResponseBody
    @RequestMapping("feedback")
    public Object feedback(HttpServletRequest request) {
        //获取用户信息，判断是否登录
        TbUser user = (TbUser) request.getSession().getAttribute("user");
        //反馈信息
        if(user != null){
            String content = request.getParameter("content");
            if(content.trim().length() != 0){
                TbFeedback tbFeedback = new TbFeedback();
                tbFeedback.setUserId(user.getId());
                tbFeedback.setContent(content);
                Integer integer = feedbackService.addFeedback(tbFeedback);
                if (integer != 0) {
                    return "反馈成功";
                } else {
                    return "反馈失败";
                }
            }else {
                return "反馈内容不能为空";
            }
        }else {
            return "请登录";
        }
    }
}
